package com.hethongviet.preventingmachine.models;

import java.util.Timer;
import java.util.TimerTask;

import android.util.Log;
import android.view.View;

import com.hethongviet.preventingmachine.helps.OnSMSMessageFailListener;

public class Transaction
{
	private String messageSend = null;
	private String messageReceive = null;
	private String id = null;
	private String codeSend = null;
	private String codeReceive = null;
	private String recipient = null;

	private int messageFailId = 0;
	private OnSMSMessageFailListener onSMSMessageFailListener = null;
	private boolean isFail = false;

	private Timer timerOut = null;
	private View viewRelay = null;

	public Transaction(OnSMSMessageFailListener failListener, int timeOut,
			int msgFailId, View view)
	{
		onSMSMessageFailListener = failListener;
		messageFailId = msgFailId;
		this.setViewRelay(view);

		TimerTask timerTask = new TimerTask() {

			@Override
			public void run()
			{
				isFail = true;
				Log.d("Transaction", "TIME OUT SMS!!!!!!!!!!!!!");

				onSMSMessageFailListener.onSMSMessageFail(Transaction.this, messageFailId);

			}
		};

		timerOut = new Timer();
		timerOut.schedule(timerTask, timeOut);
	}

	public void success()
	{
		isFail = false;
		if (timerOut != null)
		{
			timerOut.cancel();
			timerOut = null;
		}
	}

	public boolean isSolved()
	{
		return messageReceive != null;
	}

	public String getMessageWillSend()
	{
		return codeSend + messageSend + id;
	}

	public String getMessageWillSendNoID()
	{
		return codeSend + messageSend;
	}

	public String getMessageSent()
	{
		return messageSend;
	}

	public void setMessageSend(String messageSend)
	{
		this.messageSend = messageSend;
	}

	public String getMessageReceive()
	{
		return messageReceive;
	}

	public void setMessageReceive(String messageReceive)
	{
		this.messageReceive = messageReceive;
	}

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public String getCodeSend()
	{
		return codeSend;
	}

	public void setCodeSend(String codeSend)
	{
		this.codeSend = codeSend;
	}

	public String getCodeReceive()
	{
		return codeReceive;
	}

	public void setCodeReceive(String codeReceive)
	{
		this.codeReceive = codeReceive;
	}

	public Timer getTimerOut()
	{
		return timerOut;
	}

	public void setTimerOut(Timer timerOut)
	{
		this.timerOut = timerOut;
	}

	public boolean isFail()
	{
		return isFail;
	}

	public void setFail(boolean isFail)
	{
		this.isFail = isFail;
	}

	public String getRecipient()
	{
		return recipient;
	}

	public void setRecipient(String recipient)
	{
		this.recipient = recipient;
	}

	public View getViewRelay()
	{
		return viewRelay;
	}

	public void setViewRelay(View view)
	{
		this.viewRelay = view;
	}

}
